package omg.ligong.dao;

import omg.ligong.dao.impl.CollegeDAOImpl;
import omg.ligong.dao.impl.CourseClassDAOImpl;
import omg.ligong.dao.impl.StudentDAOImpl;

public class DAOFactory {
	private static DAOFactory _ins = null;;
	private StudentDAO studentManager = null;
	private CourseClassDAO courseClassManager = null;
	private CollegeDAO collegeMgr = null;

	private DAOFactory() {
	}

	public static DAOFactory getInstance() {
		if (_ins == null) {
			synchronized (DAOFactory.class) {
				if (_ins == null) {
					_ins = new DAOFactory();
				}
			}
		}
		return _ins;
	}

	/**
	 * 获取StudentDAO接口的实例
	 * 
	 * @return
	 */
	public StudentDAO getStudentManager() {
		if (studentManager == null) {
			synchronized (StudentDAOImpl.class) {
				if (studentManager == null) {
					studentManager = new StudentDAOImpl();
				}
			}
		}
		return studentManager;
	}

	public CourseClassDAO getCourseClassManager() {
		if (courseClassManager == null) {
			synchronized (CourseClassDAOImpl.class) {
				if (courseClassManager == null) {
					courseClassManager = new CourseClassDAOImpl();
				}
			}
		}
		return courseClassManager;
	}

	public CollegeDAO getCollegeManager() {
		if (collegeMgr == null) {
			synchronized (CollegeDAOImpl.class) {
				if (collegeMgr == null) {
					collegeMgr = new CollegeDAOImpl();
				}
			}
		}
		return collegeMgr;
	}

	public void releaseInstance() {
		_ins = null;
		studentManager = null;
		courseClassManager = null;
		collegeMgr = null;
	}
}
